﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace An_Im.Theme.Custom
{

    public class AnListBox : ListBox
    {
        /// <summary>
        /// 用于解决ListBox点击后自动跳转到首项开始的问题。
        /// 来源 https://www.cnblogs.com/cuigzh/p/14107212.html
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnRequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
        {
            e.Handled = true;
        }

        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            if (SelectionMode != SelectionMode.Single)
                SelectedItems.Clear();
            else
                SelectedItem = null;
            base.OnMouseLeftButtonDown(e);
        }

        static AnListBox()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(AnListBox), new FrameworkPropertyMetadata(typeof(AnListBox)));
        }
    }
}
